<template>
	<slot></slot>
	<!-- 公用的商品列表组件 -->
	<view class="card-view">
		<view class="card-item" v-for="(item,index) in card" :key="index" @click="goDetail(item._id,item.video_url)">
			<view class="card-image">
				<image :src="item.goods_cover" mode="aspectFill"></image>
			</view>
			<view class="card-title overflow">{{item.goods_title}}</view>
			<view class="card-price">
				<text>¥{{item.goods_price}}</text>
				<text>已售{{item.sold}}</text>
			</view>
		</view>
	</view>
</template>

<script setup>
	import { defineProps } from 'vue'
	const props = defineProps({ 
		card: Array
	})
	
	// 点击商品跳转详情页
	function goDetail(id, video_url) {
		// console.log("sss",video_url);
		// 商品有视频 跳转到短视频页面，没有就跳转到详情页
		if (video_url == '') {
			// console.log('跳转详情页')
			uni.navigateTo({
				url: `/pages/goods-detail/goods-detail?goods_id=${id}`
			})
		} else {
			uni.navigateTo({
				url: `/pages/short-video/short-video?goods_id=${id}`
			})
		}
	}
</script>

<style scoped>
	.card-view {
		display: flex;
		flex-wrap: wrap;
		margin: 20rpx 10rpx;
	}

	/* 每一块商品的样式 */
	.card-item {
		width: calc(50% - 10rpx*2);
		margin: 10rpx;
		background: #FFFFFF;
		border-radius: 10rpx;
	}

	.card-image {
		height: 400rpx;
	}

	.card-item image {
		width: 100%;
		height: 400rpx;
		border-top-left-radius: 10rpx;
		border-top-right-radius: 10rpx;
	}

	.card-title {
		font-size: 28rpx;
		height: 80rpx;
		line-height: 40rpx;
		margin: 10rpx 15rpx;
	}

	.card-price {
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding: 0 15rpx 15rpx 15rpx;
	}

	.card-price text:nth-child(1) {
		color: #e9445a;
		font-weight: bold;
	}

	.card-price text:nth-child(2) {
		color: #b0b1b4;
		font-size: 25rpx;
	}
</style>
